package com.assets.Check;

import android.app.Dialog;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;
import androidx.lifecycle.MediatorLiveData;
import androidx.recyclerview.widget.RecyclerView;

import com.assets.R;
import com.assets.bean.Input_item1;


import com.assets.databinding.InputAdapterItemBinding;
import com.assets.newNHF.util.LogUtils;
import com.assets.util.RequestResult;
import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.jjh.TAssetAsset;

import java.util.List;

/**
 * @作者(author): WR
 * @创建时间(date): 2022/3/4
 */
public class CheckAdapter extends RecyclerView.Adapter<CheckAdapter.CheckViewHolder> {
    private List<TAssetAsset> inputItem1List;
    private Dialog dialog;

    private MediatorLiveData<Integer> getPosition = new MediatorLiveData<>();

    public MediatorLiveData<Integer> getGetPosition() {
        return getPosition;
    }

    private RequestResult<Integer> requestResult;
    public CheckAdapter(List<TAssetAsset> inputItem1List) {
        this.inputItem1List = inputItem1List;
    }

    public void setRequestSuccess(RequestResult<Integer> requestResult){
        this.requestResult=requestResult;
    }
    @NonNull
    @Override
    public CheckViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        InputAdapterItemBinding binding = InputAdapterItemBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
        return new CheckViewHolder(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull CheckViewHolder holder, int position) {
//        Input_item1 linkeMain = inputItem1List.get(position);
        TAssetAsset tAssetAsset = inputItem1List.get(position);
        holder.mainBinding.AssetName.setText(tAssetAsset.getAssetName());
        holder.mainBinding.Section.setText(tAssetAsset.getPlace());
        holder.mainBinding.CodeNumber.setText(tAssetAsset.getAssetNumber());
        holder.mainBinding.Lou.setText(tAssetAsset.getCompany());
//        holder.mainBinding.rfidTv.setText(linkeMain.getRfid());
        holder.mainBinding.model.setText(tAssetAsset.getModel());
        holder.mainBinding.beizhu.setText("5");
        holder.mainBinding.place.setText(tAssetAsset.getDivision());
//        String image = linkeMain.getAsset_img();


//        holder.mainBinding.model.addTextChangedListener(new TextWatcher() {
//            @Override
//            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//                // TODO: 2024/2/4 这个是文本改变前
//            }
//
//            @Override
//            public void onTextChanged(CharSequence s, int start, int before, int count) {
//                // TODO: 2024/2/4 这个是文本改变中
//            }
//
//            @Override
//            public void afterTextChanged(Editable s) {
//                // TODO: 2024/2/4 这个是文本改变后
////                linkeMain.setJifang(s.toString());
//                try {
//                    inputItem1List.get(position).setConcreteNum(s.toString());
//                }catch (Exception e) {
//                    e.printStackTrace();
//                }
//
//                Log.d("改变了吗", "tAssetAsset: " + new Gson().toJson(tAssetAsset));
////                getPosition.setValue(position);
//            }
//        });

        holder.mainBinding.Lou1.setOnClickListener(v -> {

            plac.onClickListener(position);

        });

        holder.mainBinding.place1.setOnClickListener(v -> {
            plac55.onClickListener(position);
        });

//       .addTextChangedListener(new TextWatcher() {
//            @Override
//            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//
//            }
//
//            @Override
//            public void onTextChanged(CharSequence s, int start, int before, int count) {
//
//            }
//
//            @Override
//            public void afterTextChanged(Editable s) {
////                tAssetAsset.setCompany(s.toString());
//
//                try {
//                    inputItem1List.get(position).setCompany(s.toString());
//                    inputItem1List.get(position).setEdit(true);
//                }catch (Exception e) {
//                    e.printStackTrace();
//                }
//
//
//            }
//        });

//        holder.mainBinding.place.addTextChangedListener(new TextWatcher() {
//            @Override
//            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//
//            }
//
//            @Override
//            public void onTextChanged(CharSequence s, int start, int before, int count) {
//
//            }
//
//            @Override
//            public void afterTextChanged(Editable s) {
//                try {
//                    inputItem1List.get(position).setDivision(s.toString());
//                    inputItem1List.get(position).setEdit(true);
//                }catch (Exception e) {
//                    e.printStackTrace();
//                }
//
////                tAssetAsset.setDivision(s.toString());
//            }
//        });

    }

    @Override
    public int getItemCount() {
        return inputItem1List.size();
    }

    public interface onClick {
        void result(Integer position);
    }

    private onClick onClick;

    public void setOnClick(CheckAdapter.onClick onClick) {
        this.onClick = onClick;
    }

    public plac plac;

    public interface plac {

        void onClickListener(int position);

    }

    public void setPlac(plac plac) {
        this.plac = plac;
    }

    public plac55 plac55;

    public interface plac55 {

        void onClickListener(int position);

    }

    public void setPlac1(plac55 plac) {
        this.plac55 = plac;
    }

    class CheckViewHolder extends RecyclerView.ViewHolder {
        private InputAdapterItemBinding mainBinding;

        public CheckViewHolder(@NonNull InputAdapterItemBinding binding) {
            super(binding.getRoot());
            mainBinding = binding;
//            binding.getRoot().setOnClickListener(v -> {
//                if (onClick != null) {
//                    onClick.result(getAdapterPosition());
//                }
//            });
        }
    }


}
